package com.zueb.stumanage.login

import android.annotation.SuppressLint
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.navigation.Navigation
import com.zueb.stumanage.R
import com.zueb.stumanage.databinding.FragmentLoginBinding


class LoginFragment: Fragment() {

    private var viewModel:LoginViewModel?=null
    @SuppressLint("ResourceType")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        viewModel = ViewModelProviders.of(this).get(LoginViewModel::class.java).apply {
            loginOK.observe(this@LoginFragment, Observer {ok->
                if(ok){
    /*              Navigation.findNavController(requireView()).navigate(R.id.action_fg_login_to_fg_main)*/
                    Log.d("MyTag","去掉栈顶")
                    Navigation.findNavController(activity!!, R.id.nav_host_main).navigateUp()
                }
            })
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val binding:FragmentLoginBinding = FragmentLoginBinding.inflate(inflater, container, false)
        binding.vm = viewModel
        return binding.root
    }
}
